package com.qianfeng.interceptor;

import com.qianfeng.exception.FindDataException;
import com.qianfeng.pojo.BaseUser;
import com.qianfeng.pojo.SysUserInfo;
import com.qianfeng.status.ResultCode;
import com.qianfeng.utils.LoginUsersUtils;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/*
 *@Description:
 *@author:刘哥
 *@Date:86180 2022/9/7 18:56
 */
@Component
//@Aspect
public class LoginInterceptor{
    @Pointcut("execution(* com.qianfeng.service.impl.CategoryServiceImpl.*(..))")
    public void qiedian(){

    }
    @Pointcut("execution(* com.qianfeng.service.impl.SceneServiceImpl.*(..))")
    public void scene(){

    }
    @Pointcut("execution(* com.qianfeng.service.impl.DeviceServiceImpl.*(..))")
    public void device(){

    }
    @Before("qiedian()")
    public boolean preHandle() throws Exception {
        BaseUser loginUser = LoginUsersUtils.getLoginUser();
        Assert.isTrue(loginUser != null, () -> {
            throw new FindDataException("没有查询到用户,请先登录", ResultCode.Not_LOGIN_USERS_Not);
        });
        return true;
    }
    @Before("scene()")
    public boolean sceneLogin() throws Exception {
        BaseUser loginUser = LoginUsersUtils.getLoginUser();
        Assert.isTrue(loginUser != null, () -> {
            throw new FindDataException("没有查询到用户,请先登录", ResultCode.Not_LOGIN_USERS_Not);
        });
        return true;
    }
    @Before("device()")
    public boolean deviceLogin() throws Exception {
        BaseUser loginUser = LoginUsersUtils.getLoginUser();
        Assert.isTrue(loginUser != null, () -> {
            throw new FindDataException("没有查询到用户,请先登录", ResultCode.Not_LOGIN_USERS_Not);
        });
        return true;
    }
}
